<div class="main layui-clear">
	<h2 class="page-title">发表问题</h2>
	  
	  <!-- <div class="fly-none">并无权限</div> -->
	
	  <div class="layui-form layui-form-pane">
	    <form action="/jsluntan/topic/save.html" method="post">
	      <div class="layui-form-item">
	        <label for="L_title" class="layui-form-label">标题</label>
	        <div class="layui-input-block">
	          <input type="text" id="L_title" name="title" required lay-verify="required" autocomplete="off" class="layui-input">
	        </div>
	      </div>
	      <div class="layui-form-item layui-form-text">
	        <div class="layui-input-block">
	          <textarea id="content" name="content" required lay-verify="required" placeholder="请输入内容" class="layui-textarea fly-editor" style="height: 260px;"></textarea>
	        </div>
	        <label for="content" class="layui-form-label" style="top: -2px;">描述</label>
	      </div>
	      <div class="layui-form-item" style="display: none;">
	        <label for="L_title" class="layui-form-label">附件名称</label>
	        <div class="layui-input-block">
	          <input type="text" id="L_filename" name="filename" autocomplete="off" class="layui-input">
	        </div>
	      </div>
	      <div class="layui-form-item" style="display: none;">
	        <label for="L_title" class="layui-form-label">附件链接</label>
	        <div class="layui-input-block">
	          <input type="text" id="L_fileurl" name="fileurl" autocomplete="off" class="layui-input">
	        </div>
	      </div>
	      
	      <div class="layui-form-item">
			<input type="file" name="file" lay-type="file" class="layui-upload-file">
			<span id="files"></span>
	      </div>
	      
	      <div class="layui-form-item">
	        <div class="layui-inline">
	          <label class="layui-form-label">所在类别</label>
	          <div class="layui-input-block">
	            <select lay-verify="required" name="cate">
	              <option></option>
	              <option value="问题咨询" selected="selected">问题咨询</option>
	              <option value="改进建议">改进建议</option>
	              <option value="产品介绍">产品介绍</option>
	            </select>
	          </div>
	        </div>
	        <div class="layui-inline">
	          <label class="layui-form-label">悬赏</label>
	          <div class="layui-input-block">
	            <select name="price">
	              <option value="5" selected>5</option>
	              <option value="10">10</option>
	              <option value="20">20</option>
	              <option value="50">50</option>
	              <option value="100">100</option>
	            </select>
	          </div>
	        </div>
	      </div>
	      <div class="layui-form-item">
	        <button class="layui-btn" lay-filter="*" lay-submit onclick="if(layedit){layedit.sync(index);}">立即发布</button>
	      </div>
	    </form>
	  </div>
	</div>
</div>
<script>
	var layedit, index;
	layui.use(['form' , 'layedit'], function(){
  		var form = layui.form() ;
  		layedit = layui.layedit;
  		layedit.set({
	  		uploadImage: {
	    		url: '/jsluntan/topic/upload.html' //接口url
	    		,type: 'post' //默认post
	  		}
  		});
  		index = layedit.build('content'); //建立编辑器
	});

	layui.use('upload', function(){
  		layui.upload({
  			url: '/jsluntan/topic/upload.html',
  			before:function(res){
  				console.log("before res : " + res.value);
  			},
  			success: function(res){
  				debugger;
  		    	console.log("success res : " + res.data.src); //上传成功返回值，必须为json格式
  		    	var b = document.getElementById("files");
  		    	var html = "<div class='fileDiv'>"
  		    				+"<a style='margin-left:15px;' href='"+res.data.path+"' target='_blank'> " + res.data.title + "</a>"
  		    				+"<img src='/jsluntan/images/delete.png' class='edit-file-delete'>"
  		    				+"</div>"
  		    	b.innerHTML += html;

  		    	var fname = document.getElementById("L_filename");
  		    	if(fname.value == null || fname.value == "") {
  		    		fname.value = res.data.title;
  		    	} else {
  		    		fname.value = fname.value + "," + res.data.title;
  		    	}
  		    	

  		    	var furl = document.getElementById("L_fileurl");
  		    	if(furl.value == null || furl.value == "") {
  		    		furl.value = res.data.path;
  		    	} else {
  		    		furl.value = furl.value + "," + res.data.path;
  		    	}
  		    	$("#files").children("div").each(function(){
	  		  		$(this).children("img").on("click",function(){
	  		  			debugger;
	  		  			var href = $(this).siblings("a").attr("href");
	  		  			var title = $(this).siblings("a").text();
	  		  			$(this).parent("div").remove();
	  		  		})
	  		  	})
  		  	}
  		});
  	});
	
		


</script>